package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Travel;
import cn.wolfcode.luowowo.article.domain.TravelCommend;
import cn.wolfcode.luowowo.article.query.TravelCommendQuery;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/travelCommend")
public class TravelCommendController {


    @Reference
    private ITravelCommendService travelCommendService;

    @Reference
    private ITravelService travelService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") TravelCommendQuery qo, Model model) {
        model.addAttribute("pageInfo", travelCommendService.query(qo));
        model.addAttribute("travels", travelService.getTravelByState(2));
        return "travelCommend/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(TravelCommend travelCommend) {
        try {
            travelCommendService.saveOrUpdate(travelCommend);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.FALSE;
        }
        return AjaxResult.SUCCESS;
    }
}